<template>
  <div class="apply">
    <nav-bar title="申请"></nav-bar>
    <div>
      <van-cell-group title="申请成为圈子"></van-cell-group>
      <van-form @submit="onSubmit">
        <van-field
            v-model="circleName"
            name="circleName"
            label="圈子"
            placeholder="圈子"
            :rules="[{ required: true, message: '请填写圈子名称' }]"
        />
        <van-field
            type="textarea"
            v-model="description"
            name="description"
            label="描述"
            rows="5"
            placeholder="描述"
            :rules="[{ required: true, message: '请填写描述' }]"
        />

        <van-field name="typeId" label="类型" :rules="[{ required: true, message: '请选择活动类型' }]">
          <template #input>
            <van-radio-group v-model="typeId" direction="horizontal">
              <van-radio name="1">学习</van-radio>
              <van-radio name="2">比赛</van-radio>
              <van-radio name="3">社团</van-radio>
            </van-radio-group>
          </template>
        </van-field>

        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">
            提交
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import NavBar from "@/components/NavBar/NavBar";
import {Toast} from "vant";

export default {
  name: "Apply",
  components: {
    NavBar
  },
  data() {
    return {
      circleName: '',
      description: '',
      typeId: ''
    }
  },
  methods: {
    onSubmit(e) {
      let formData = _g.toFormData(e);
      axios.post('/circle/applyForCircle', {...e}).then(res => {
        if (res.status === 200) {
          Toast.success(res.msg);
          this.isLoading = false;
          this.$router.go(-1);
        } else {
          Toast.fail(res.msg);
        }
      }).catch(err => {
        Toast.fail(err.msg);
      })
    }
  }
}
</script>

<style scoped>
.van-doc-demo-block__title {
  margin: 0;
  padding: 32px 16px 16px;
  color: rgba(74, 97, 108, 0.6);
  font-weight: normal;
  font-size: 14px;
  line-height: 16px;
}
</style>
